import panel from './panel.vue'
const DEVICE_CATEGORY = [
  "压力传感器",
  "可燃气体报警仪",
  "有毒气体报警仪",
  "氧化分析仪",
  "泄漏报警器",
  "流量监测仪",
  "液位传感器",
  "温度传感器",
  "氧气分析仪",
  "可燃气体检测"
];

const DEVICE_CATEGORY_NORMAL = [
  require("./设备_压力_normal .png"),
  require("./设备_可燃_normal.png"),
  require("./设备_有毒_normal.png"),
  require("./设备_氧化_normal.png"),
  require("./设备_泄漏_normal.png"),
  require("./设备_流量_normal.png"),
  require("./设备_液位_normal.png"),
  require("./设备_温度_normal.png"),
  require("./设备_氧化_normal.png"),
  require("./设备_可燃_normal.png")
];

const DEVICE_CATEGORY_ALARM = [
  require("./设备_压力_alarm.png"),
  require("./设备_可燃_alarm.png"),
  require("./设备_有毒_alarm.png"),
  require("./设备_氧化_alarm.png"),
  require("./设备_泄漏_alarm.png"),
  require("./设备_流量_alarm.png"),
  require("./设备_液位_alarm.png"),
  require("./设备_温度_alarm.png"),
  require("./设备_氧化_alarm.png"),
  require("./设备_可燃_normal.png")
];

const source = {
  collectionName: "measure_automation",
  options: {
    include: ["GridId", "EnterpriseName"],
    or: [{ exists: "GridId" }, { exists: "Coordinate" }]
  },
  liveEvents: ["create", "update", "delete"]
}
const layer = {
  zoom: [16, 30],
  infoWindow: {
    title: "DeviceName",
    component: panel
  },
  marker: {
    coordinate: "Coordinate",
    src: {
      normal: prop => {
        let index = DEVICE_CATEGORY.indexOf(prop.DeviceCategory);
        return index > -1 ? DEVICE_CATEGORY_NORMAL[index] : "";
      },
      alarm: prop => {
        let index = DEVICE_CATEGORY.indexOf(prop.DeviceCategory);
        return index > -1 ? DEVICE_CATEGORY_ALARM[index] : "";
      }
    },
    text: prop => `${prop.value}${prop.EngineeringUnits}`,
    rule: prop => {
      if (!prop.value) return "alarm";
      if (prop.AlarmUpperThreshold && prop.AlarmLowerThreshold) {
        return prop.value - prop.AlarmUpperThreshold < 0 &&
          prop.value - prop.AlarmLowerThreshold > 0
          ? "normal"
          : "alarm";
      } else {
        return "normal";
      }
    }
  }
}

export default {
  sources: { sensor: source },
  layers: { sensor: layer }
}
